import React, { Component } from 'react';
import PropTypes from "prop-types";
import {
    Form,
    Input
} from "antd";

const Item = Form.Item


// 更新分类的form组件
export default class UpdateForm extends Component {
    // ref
    updateRef = React.createRef();


    componentDidMount() {
        this.props.setMyUpdateForm(this.updateRef);
    }

    // 对props进行限制
    static propTypes = {
        categoryName: PropTypes.string.isRequired,
        setMyUpdateForm: PropTypes.func.isRequired,
    }

    render() {
        const {categoryName} = this.props;
        return (
            <Form ref={this.updateRef}>
                <Item 
                name="categoryName" 
                initialValue={categoryName}
                rules={[
                    {
                        required: true,
                        message: "分类名称必须输入",
                    },
                ]} 
                >
                    <Input placeholder="请输入分类名称" />
                </Item>
            </Form>
        )
    }
}


